<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Captcha extends MY_Controller {
	
	function __construct()
    {
        parent::__construct();
    }
	
	public function index(){
	    $this->load->helper('captcha');
	    $vals = array(
	        'word'          => '',
	        'img_path'      => './application/cache/captcha/',
	        'img_url'       => base_url().'/application/cache/captcha/',
	        'font_path'     => './system/fonts/texb.ttf',
	        'img_width'     => '90',
	        'img_height'    => '38',
	        'expiration'    => 7200,
	        'word_length'   => 4,
	        'font_size'     => 18,
	        'img_id'        => 'Imageid',
	        'pool'          => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
	         
	        // White background and border, black text and red grid
	        'colors'        => array(
	            'background' => array(255, 255, 255),
	            'border' => array(255, 255, 255),
	            'text' => array(0, 0, 0),
	            'grid' => array(255, 40, 40)
	        )
	    );
	     
	    $cap = create_captcha($vals);
	    
	    $data = array(
	        'captcha_time'  => $cap['time'],
	        'ip_address'    => $this->input->ip_address(),
	        'word'          => $cap['word']
	    );
	    
	    $query = $this->db->insert_string('captcha', $data);
	    $this->db->query($query);
	    
	    echo $cap['image'];
	}
	
}
